package logic

import (
	"context"
	"doc-manage/moder"

	"doc-manage/docrpc/docrpc"
	"doc-manage/docrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateLogic {
	return &UserUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserUpdateLogic) UserUpdate(in *docrpc.UserDelRequest) (*docrpc.UserUpdateResponse, error) {
	// todo: add your logic here and delete this line
	var user moder.User
	user = moder.User{
		Username: user.Username,
		Password: user.Password,
	}
	err := user.UserUpdate(moder.DB, in.UserId)
	if err != nil {
		return nil, err
	}

	return &docrpc.UserUpdateResponse{
		UserId: int64(user.ID),
	}, nil
}
